import { Byte } from '../../api/io/Byte';
import { XunFengSdk } from './XunFengSdk';
import { PlayerInfo } from './PlayerInfo';
import { PlayerServer } from './PlayerServer';
import { Vip } from './Vip';
import { GameStage } from './GameStage';
import { EquipManager } from './EquipManager';
import { RandomEvent } from './RandomEvent';
import { Lottery } from './Lottery';
import { Train } from './Train';
import { PetManager } from './PetManager';
import { TrialTower } from './TrialTower';
import { MailBox } from './MailBox';
import { WorldBoss } from './WorldBoss';
import { LegionBoss } from './LegionBoss';
import { Mission } from './Mission';
import { Welfare } from './Welfare';
import { Talent } from './Talent';
import { ShopManager } from './ShopManager';
import { HandBook } from './HandBook';
import { GardenManager } from './GardenManager';
import { HuangXiaoxiManager } from './HuangXiaoxiManager';
import { OuterRewards } from './OuterRewards';
import { HashMap } from '../../api/struct/HashMap';
import { Activity } from './Activity';
import { Arena } from './Arena';
import { LegionManager } from './LegionManager';
import { PlayerTitle } from './PlayerTitle';
import { ChatManager } from './ChatManager';
import { ClientStorage } from './ClientStorage';
import { ITimer } from '../../api/timer/ITimer';
import { IAsync } from '../../api/event/IAsync';
import { MathUtils } from '../../api/math/MathUtils';



/**玩家信息属性枚举*/
export const enum E_Player {
	/**玩家id*/
	PLAYER_ID = 0,
	/**用户id*/
	USER_ID = 1,
	/**注册渠道*/
	CHANNEL = 2,
	/**巽风sdk信息*/
	XUN_FENG_SDK = 3,
	/**是否封号*/
	BANNED = 4,
	/**玩家信息*/
	PLAYER_INFO = 5,
	/**服务器信息*/
	SERVER = 6,
	/**vip信息*/
	VIP = 7,
	/**战斗场景信息*/
	BATTLE_STAGE = 8,
	/**装备*/
	EQUIP_MANAGER = 9,
	/**随机事件*/
	RANDOM_EVENT = 10,
	/**抽卡*/
	LOTTERY = 11,
	/**训练*/
	TRAIN = 12,
	/**宠物*/
	PET_MANAGER = 13,
	/**试练塔*/
	TRIAL_TOWER = 14,
	/**邮箱*/
	MAIL_BOX = 15,
	/**世界boss*/
	WORLD_BOSS = 16,
	/**军团boss*/
	LEGION_BOSS = 17,
	/**任务*/
	MISSION = 18,
	/**福利*/
	WELFARE = 19,
	/**天赋*/
	TALENT = 20,
	/**商店*/
	SHOP_MANAGER = 21,
	/**图鉴*/
	HAND_BOOK = 22,
	/**庭院管理器*/
	GARDEN_MANAGER = 23,
	/**黄小西管理器*/
	HUANG_XIAOXI_MANAGER = 24,
	/**玩家待领取的外部奖励*/
	OUTER_REWARDS = 25,
	/**自增id*/
	INC_ID = 26,
	/**道具数量*/
	ITEM_NUM = 27,
	/**祝福等级*/
	PRAY_LEVEL = 29,
	/**活动*/
	ACTIVITY = 30,
	/**竞技场*/
	ARENA = 31,
	/**军团*/
	LEGION = 32,
	/**称号*/
	TITLE = 33,
	/**聊天*/
	CHAT_MANAGER = 34,
	/**客户端自定义存储*/
	CLIENT_STORAGE = 36,
	/**世界boss2*/
	WORLD_BOSS2 = 37,
	/**世界boss3*/
	WORLD_BOSS3 = 38,
	/**枚举数量*/
	EnumCount = 39
}


/**玩家信息*/
export class Player {
	/**事件ID*/
	public static readonly EVENT_ID = 'STRUCT_DATA_PLAYER_EVENT_ID';
	/**整体更新事件ID（部分只需要监听整体变化）*/
	public static readonly TOTAL_EVENT_ID = 'STRUCT_DATA_PLAYER_TOTAL_EVENT_ID';
	/**缓存池*/
	private static POOL: Player[] = [];

	/**创建入口*/
	public static create(json?: string): Player {
		const c = this.POOL.pop() || new Player();
		c._destroyed = false;
		c.resetProperty();
		if (json) {
			c.parse(json);
		}
		return c;
	}


	/**已释放*/
	protected _destroyed = false;
	/**玩家id (uint32)*/
	protected _playerId: number;
	/**用户id (uint32)*/
	protected _userId: number;
	/**注册渠道*/
	protected _channel: string;
	/**巽风sdk信息*/
	protected _xunFengSdk: XunFengSdk = null;
	/**是否封号*/
	protected _banned: boolean;
	/**玩家信息*/
	protected _playerInfo: PlayerInfo = null;
	/**服务器信息*/
	protected _server: PlayerServer = null;
	/**vip信息*/
	protected _vip: Vip = null;
	/**战斗场景信息*/
	protected _battleStage: GameStage = null;
	/**装备*/
	protected _equipManager: EquipManager = null;
	/**随机事件*/
	protected _randomEvent: RandomEvent = null;
	/**抽卡*/
	protected _lottery: Lottery = null;
	/**训练*/
	protected _train: Train = null;
	/**宠物*/
	protected _petManager: PetManager = null;
	/**试练塔*/
	protected _trialTower: TrialTower = null;
	/**邮箱*/
	protected _mailBox: MailBox = null;
	/**世界boss*/
	protected _worldBoss: WorldBoss = null;
	/**军团boss*/
	protected _legionBoss: LegionBoss = null;
	/**任务*/
	protected _mission: Mission = null;
	/**福利*/
	protected _welfare: Welfare = null;
	/**天赋*/
	protected _talent: Talent = null;
	/**商店*/
	protected _shopManager: ShopManager = null;
	/**图鉴*/
	protected _handBook: HandBook = null;
	/**庭院管理器*/
	protected _gardenManager: GardenManager = null;
	/**黄小西管理器*/
	protected _huangXiaoxiManager: HuangXiaoxiManager = null;
	/**玩家待领取的外部奖励*/
	protected _outerRewards: OuterRewards = null;
	/**自增id (uint8, uint32)*/
	protected _incId: HashMap<number, number> = null;
	/**道具数量 (int32, uint32)*/
	protected _itemNum: HashMap<number, number> = null;
	/**祝福等级 (uint32, uint16)*/
	protected _prayLevel: HashMap<number, number> = null;
	/**活动*/
	protected _activity: Activity = null;
	/**竞技场*/
	protected _arena: Arena = null;
	/**军团*/
	protected _legion: LegionManager = null;
	/**称号*/
	protected _title: PlayerTitle = null;
	/**聊天*/
	protected _chatManager: ChatManager = null;
	/**客户端自定义存储*/
	protected _clientStorage: ClientStorage = null;
	/**世界boss2*/
	protected _worldBoss2: WorldBoss = null;
	/**世界boss3*/
	protected _worldBoss3: WorldBoss = null;


	/**构建函数-私有，防止外部创建*/
	private constructor() {
	}


	/**释放*/
	public destroy(): void {
		if (this._destroyed) {
			return;
		}
		this._destroyed = true;
		this.resetProperty(true);
		if (Player.POOL.indexOf(this) === -1) {
			Player.POOL.push(this);
		}
	}

	/**玩家id*/
	public get playerId() {
		return this._playerId;
	}


	/**玩家id*/
	public set playerId(v: number) {
		this._playerId = v;
	}


	/**用户id*/
	public get userId() {
		return this._userId;
	}


	/**用户id*/
	public set userId(v: number) {
		this._userId = v;
	}


	/**注册渠道*/
	public get channel() {
		return this._channel;
	}


	/**注册渠道*/
	public set channel(v: string) {
		this._channel = v;
	}


	/**巽风sdk信息*/
	public get xunFengSdk() {
		return this._xunFengSdk;
	}


	/**是否封号*/
	public get banned() {
		return this._banned;
	}


	/**是否封号*/
	public set banned(v: boolean) {
		this._banned = v;
	}


	/**玩家信息*/
	public get playerInfo() {
		return this._playerInfo;
	}


	/**服务器信息*/
	public get server() {
		return this._server;
	}


	/**vip信息*/
	public get vip() {
		return this._vip;
	}


	/**战斗场景信息*/
	public get battleStage() {
		return this._battleStage;
	}


	/**装备*/
	public get equipManager() {
		return this._equipManager;
	}


	/**随机事件*/
	public get randomEvent() {
		return this._randomEvent;
	}


	/**抽卡*/
	public get lottery() {
		return this._lottery;
	}


	/**训练*/
	public get train() {
		return this._train;
	}


	/**宠物*/
	public get petManager() {
		return this._petManager;
	}


	/**试练塔*/
	public get trialTower() {
		return this._trialTower;
	}


	/**邮箱*/
	public get mailBox() {
		return this._mailBox;
	}


	/**世界boss*/
	public get worldBoss() {
		return this._worldBoss;
	}


	/**军团boss*/
	public get legionBoss() {
		return this._legionBoss;
	}


	/**任务*/
	public get mission() {
		return this._mission;
	}


	/**福利*/
	public get welfare() {
		return this._welfare;
	}


	/**天赋*/
	public get talent() {
		return this._talent;
	}


	/**商店*/
	public get shopManager() {
		return this._shopManager;
	}


	/**图鉴*/
	public get handBook() {
		return this._handBook;
	}


	/**庭院管理器*/
	public get gardenManager() {
		return this._gardenManager;
	}


	/**黄小西管理器*/
	public get huangXiaoxiManager() {
		return this._huangXiaoxiManager;
	}


	/**玩家待领取的外部奖励*/
	public get outerRewards() {
		return this._outerRewards;
	}


	/**设置自增id*/
	public putIncId(k: number, v: number): number {
		const ov = this._incId.put(k, v);
		return ov || 0;
	}


	/**获取自增id*/
	public getIncId(k: number) {
		return this._incId.get(k) || 0;
	}


	/**删除自增id*/
	public removeIncId(k: number): number {
		const ov = this._incId.remove(k);
		return ov || 0;
	}


	/**获取自增id映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getIncIdKeys(): number[] {
		return this._incId.getKeys();
	}


	/**获取自增id映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getIncIdValues(): number[] {
		return this._incId.getValues();
	}


	/**清空自增id映射表*/
	public clearIncIdMap(): void {
		this._incId.clear();
	}


	/**设置道具数量*/
	public putItemNum(k: number, v: number): number {
		const ov = this._itemNum.put(k, v);
		return ov || 0;
	}


	/**获取道具数量*/
	public getItemNum(k: number) {
		return this._itemNum.get(k) || 0;
	}


	/**删除道具数量*/
	public removeItemNum(k: number): number {
		const ov = this._itemNum.remove(k);
		return ov || 0;
	}


	/**获取道具数量映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getItemNumKeys(): number[] {
		return this._itemNum.getKeys();
	}


	/**获取道具数量映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getItemNumValues(): number[] {
		return this._itemNum.getValues();
	}


	/**清空道具数量映射表*/
	public clearItemNumMap(): void {
		this._itemNum.clear();
	}


	/**设置祝福等级*/
	public putPrayLevel(k: number, v: number): number {
		const ov = this._prayLevel.put(k, v);
		return ov || 0;
	}


	/**获取祝福等级*/
	public getPrayLevel(k: number) {
		return this._prayLevel.get(k) || 0;
	}


	/**删除祝福等级*/
	public removePrayLevel(k: number): number {
		const ov = this._prayLevel.remove(k);
		return ov || 0;
	}


	/**获取祝福等级映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getPrayLevelKeys(): number[] {
		return this._prayLevel.getKeys();
	}


	/**获取祝福等级映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getPrayLevelValues(): number[] {
		return this._prayLevel.getValues();
	}


	/**清空祝福等级映射表*/
	public clearPrayLevelMap(): void {
		this._prayLevel.clear();
	}


	/**活动*/
	public get activity() {
		return this._activity;
	}


	/**竞技场*/
	public get arena() {
		return this._arena;
	}


	/**军团*/
	public get legion() {
		return this._legion;
	}


	/**称号*/
	public get title() {
		return this._title;
	}


	/**聊天*/
	public get chatManager() {
		return this._chatManager;
	}


	/**客户端自定义存储*/
	public get clientStorage() {
		return this._clientStorage;
	}


	/**世界boss2*/
	public get worldBoss2() {
		return this._worldBoss2;
	}


	/**世界boss3*/
	public get worldBoss3() {
		return this._worldBoss3;
	}



	/**通过枚举获取值*/
	public getV(k: E_Player): any {
		switch (k) {
			case E_Player.PLAYER_ID: return this._playerId;
			case E_Player.USER_ID: return this._userId;
			case E_Player.CHANNEL: return this._channel;
			case E_Player.XUN_FENG_SDK: return this._xunFengSdk;
			case E_Player.BANNED: return this._banned;
			case E_Player.PLAYER_INFO: return this._playerInfo;
			case E_Player.SERVER: return this._server;
			case E_Player.VIP: return this._vip;
			case E_Player.BATTLE_STAGE: return this._battleStage;
			case E_Player.EQUIP_MANAGER: return this._equipManager;
			case E_Player.RANDOM_EVENT: return this._randomEvent;
			case E_Player.LOTTERY: return this._lottery;
			case E_Player.TRAIN: return this._train;
			case E_Player.PET_MANAGER: return this._petManager;
			case E_Player.TRIAL_TOWER: return this._trialTower;
			case E_Player.MAIL_BOX: return this._mailBox;
			case E_Player.WORLD_BOSS: return this._worldBoss;
			case E_Player.LEGION_BOSS: return this._legionBoss;
			case E_Player.MISSION: return this._mission;
			case E_Player.WELFARE: return this._welfare;
			case E_Player.TALENT: return this._talent;
			case E_Player.SHOP_MANAGER: return this._shopManager;
			case E_Player.HAND_BOOK: return this._handBook;
			case E_Player.GARDEN_MANAGER: return this._gardenManager;
			case E_Player.HUANG_XIAOXI_MANAGER: return this._huangXiaoxiManager;
			case E_Player.OUTER_REWARDS: return this._outerRewards;
			case E_Player.INC_ID: return this._incId;
			case E_Player.ITEM_NUM: return this._itemNum;
			case E_Player.PRAY_LEVEL: return this._prayLevel;
			case E_Player.ACTIVITY: return this._activity;
			case E_Player.ARENA: return this._arena;
			case E_Player.LEGION: return this._legion;
			case E_Player.TITLE: return this._title;
			case E_Player.CHAT_MANAGER: return this._chatManager;
			case E_Player.CLIENT_STORAGE: return this._clientStorage;
			case E_Player.WORLD_BOSS2: return this._worldBoss2;
			case E_Player.WORLD_BOSS3: return this._worldBoss3;
			default: return null;
		}
	}


	/**通过枚举设置值*/
	public setV(k: E_Player, v: any): void {
		switch (k) {
			case E_Player.PLAYER_ID: this._playerId = v; break;
			case E_Player.USER_ID: this._userId = v; break;
			case E_Player.CHANNEL: this._channel = v; break;
			case E_Player.XUN_FENG_SDK: this._xunFengSdk = v; break;
			case E_Player.BANNED: this._banned = v; break;
			case E_Player.PLAYER_INFO: this._playerInfo = v; break;
			case E_Player.SERVER: this._server = v; break;
			case E_Player.VIP: this._vip = v; break;
			case E_Player.BATTLE_STAGE: this._battleStage = v; break;
			case E_Player.EQUIP_MANAGER: this._equipManager = v; break;
			case E_Player.RANDOM_EVENT: this._randomEvent = v; break;
			case E_Player.LOTTERY: this._lottery = v; break;
			case E_Player.TRAIN: this._train = v; break;
			case E_Player.PET_MANAGER: this._petManager = v; break;
			case E_Player.TRIAL_TOWER: this._trialTower = v; break;
			case E_Player.MAIL_BOX: this._mailBox = v; break;
			case E_Player.WORLD_BOSS: this._worldBoss = v; break;
			case E_Player.LEGION_BOSS: this._legionBoss = v; break;
			case E_Player.MISSION: this._mission = v; break;
			case E_Player.WELFARE: this._welfare = v; break;
			case E_Player.TALENT: this._talent = v; break;
			case E_Player.SHOP_MANAGER: this._shopManager = v; break;
			case E_Player.HAND_BOOK: this._handBook = v; break;
			case E_Player.GARDEN_MANAGER: this._gardenManager = v; break;
			case E_Player.HUANG_XIAOXI_MANAGER: this._huangXiaoxiManager = v; break;
			case E_Player.OUTER_REWARDS: this._outerRewards = v; break;
			case E_Player.INC_ID: this._incId = v; break;
			case E_Player.ITEM_NUM: this._itemNum = v; break;
			case E_Player.PRAY_LEVEL: this._prayLevel = v; break;
			case E_Player.ACTIVITY: this._activity = v; break;
			case E_Player.ARENA: this._arena = v; break;
			case E_Player.LEGION: this._legion = v; break;
			case E_Player.TITLE: this._title = v; break;
			case E_Player.CHAT_MANAGER: this._chatManager = v; break;
			case E_Player.CLIENT_STORAGE: this._clientStorage = v; break;
			case E_Player.WORLD_BOSS2: this._worldBoss2 = v; break;
			case E_Player.WORLD_BOSS3: this._worldBoss3 = v; break;
			default: break;
		}
	}


	/**初始化*/
	public resetProperty(fromDestroy = false): void {
		//玩家id
		this._playerId = 0;
		//用户id
		this._userId = 0;
		//注册渠道
		this._channel = '';
		//巽风sdk信息
		if (this._xunFengSdk) {
			this._xunFengSdk.destroy();
			this._xunFengSdk = null;
		}
		if (!fromDestroy) {
			this._xunFengSdk = XunFengSdk.create();
		}
		//是否封号
		this._banned = false;
		//玩家信息
		if (this._playerInfo) {
			this._playerInfo.destroy();
			this._playerInfo = null;
		}
		if (!fromDestroy) {
			this._playerInfo = PlayerInfo.create();
		}
		//服务器信息
		if (this._server) {
			this._server.destroy();
			this._server = null;
		}
		if (!fromDestroy) {
			this._server = PlayerServer.create();
		}
		//vip信息
		if (this._vip) {
			this._vip.destroy();
			this._vip = null;
		}
		if (!fromDestroy) {
			this._vip = Vip.create();
		}
		//战斗场景信息
		if (this._battleStage) {
			this._battleStage.destroy();
			this._battleStage = null;
		}
		if (!fromDestroy) {
			this._battleStage = GameStage.create();
		}
		//装备
		if (this._equipManager) {
			this._equipManager.destroy();
			this._equipManager = null;
		}
		if (!fromDestroy) {
			this._equipManager = EquipManager.create();
		}
		//随机事件
		if (this._randomEvent) {
			this._randomEvent.destroy();
			this._randomEvent = null;
		}
		if (!fromDestroy) {
			this._randomEvent = RandomEvent.create();
		}
		//抽卡
		if (this._lottery) {
			this._lottery.destroy();
			this._lottery = null;
		}
		if (!fromDestroy) {
			this._lottery = Lottery.create();
		}
		//训练
		if (this._train) {
			this._train.destroy();
			this._train = null;
		}
		if (!fromDestroy) {
			this._train = Train.create();
		}
		//宠物
		if (this._petManager) {
			this._petManager.destroy();
			this._petManager = null;
		}
		if (!fromDestroy) {
			this._petManager = PetManager.create();
		}
		//试练塔
		if (this._trialTower) {
			this._trialTower.destroy();
			this._trialTower = null;
		}
		if (!fromDestroy) {
			this._trialTower = TrialTower.create();
		}
		//邮箱
		if (this._mailBox) {
			this._mailBox.destroy();
			this._mailBox = null;
		}
		if (!fromDestroy) {
			this._mailBox = MailBox.create();
		}
		//世界boss
		if (this._worldBoss) {
			this._worldBoss.destroy();
			this._worldBoss = null;
		}
		if (!fromDestroy) {
			this._worldBoss = WorldBoss.create();
		}
		//军团boss
		if (this._legionBoss) {
			this._legionBoss.destroy();
			this._legionBoss = null;
		}
		if (!fromDestroy) {
			this._legionBoss = LegionBoss.create();
		}
		//任务
		if (this._mission) {
			this._mission.destroy();
			this._mission = null;
		}
		if (!fromDestroy) {
			this._mission = Mission.create();
		}
		//福利
		if (this._welfare) {
			this._welfare.destroy();
			this._welfare = null;
		}
		if (!fromDestroy) {
			this._welfare = Welfare.create();
		}
		//天赋
		if (this._talent) {
			this._talent.destroy();
			this._talent = null;
		}
		if (!fromDestroy) {
			this._talent = Talent.create();
		}
		//商店
		if (this._shopManager) {
			this._shopManager.destroy();
			this._shopManager = null;
		}
		if (!fromDestroy) {
			this._shopManager = ShopManager.create();
		}
		//图鉴
		if (this._handBook) {
			this._handBook.destroy();
			this._handBook = null;
		}
		if (!fromDestroy) {
			this._handBook = HandBook.create();
		}
		//庭院管理器
		if (this._gardenManager) {
			this._gardenManager.destroy();
			this._gardenManager = null;
		}
		if (!fromDestroy) {
			this._gardenManager = GardenManager.create();
		}
		//黄小西管理器
		if (this._huangXiaoxiManager) {
			this._huangXiaoxiManager.destroy();
			this._huangXiaoxiManager = null;
		}
		if (!fromDestroy) {
			this._huangXiaoxiManager = HuangXiaoxiManager.create();
		}
		//玩家待领取的外部奖励
		if (this._outerRewards) {
			this._outerRewards.destroy();
			this._outerRewards = null;
		}
		if (!fromDestroy) {
			this._outerRewards = OuterRewards.create();
		}
		//自增id
		if (this._incId) {
			this._incId.clear();
		}
		else {
			this._incId = new HashMap<number, number>();
		}
		//道具数量
		if (this._itemNum) {
			this._itemNum.clear();
		}
		else {
			this._itemNum = new HashMap<number, number>();
		}
		//祝福等级
		if (this._prayLevel) {
			this._prayLevel.clear();
		}
		else {
			this._prayLevel = new HashMap<number, number>();
		}
		//活动
		if (this._activity) {
			this._activity.destroy();
			this._activity = null;
		}
		if (!fromDestroy) {
			this._activity = Activity.create();
		}
		//竞技场
		if (this._arena) {
			this._arena.destroy();
			this._arena = null;
		}
		if (!fromDestroy) {
			this._arena = Arena.create();
		}
		//军团
		if (this._legion) {
			this._legion.destroy();
			this._legion = null;
		}
		if (!fromDestroy) {
			this._legion = LegionManager.create();
		}
		//称号
		if (this._title) {
			this._title.destroy();
			this._title = null;
		}
		if (!fromDestroy) {
			this._title = PlayerTitle.create();
		}
		//聊天
		if (this._chatManager) {
			this._chatManager.destroy();
			this._chatManager = null;
		}
		if (!fromDestroy) {
			this._chatManager = ChatManager.create();
		}
		//客户端自定义存储
		if (this._clientStorage) {
			this._clientStorage.destroy();
			this._clientStorage = null;
		}
		if (!fromDestroy) {
			this._clientStorage = ClientStorage.create();
		}
		//世界boss2
		if (this._worldBoss2) {
			this._worldBoss2.destroy();
			this._worldBoss2 = null;
		}
		if (!fromDestroy) {
			this._worldBoss2 = WorldBoss.create();
		}
		//世界boss3
		if (this._worldBoss3) {
			this._worldBoss3.destroy();
			this._worldBoss3 = null;
		}
		if (!fromDestroy) {
			this._worldBoss3 = WorldBoss.create();
		}
	}


	/**序列化*/
	public stringify(toString: boolean): string | any {
		const json: any = {};
		if (this._playerId) {
			json.playerId = this._playerId;
		}
		if (this._userId) {
			json.userId = this._userId;
		}
		if (this._channel) {
			json.channel = this._channel;
		}
		if (this._xunFengSdk) {
			json.xunFengSdk = this._xunFengSdk.stringify(false);
		}
		if (this._banned) {
			json.banned = this._banned;
		}
		if (this._playerInfo) {
			json.playerInfo = this._playerInfo.stringify(false);
		}
		if (this._server) {
			json.server = this._server.stringify(false);
		}
		if (this._vip) {
			json.vip = this._vip.stringify(false);
		}
		if (this._battleStage) {
			json.battleStage = this._battleStage.stringify(false);
		}
		if (this._equipManager) {
			json.equipManager = this._equipManager.stringify(false);
		}
		if (this._randomEvent) {
			json.randomEvent = this._randomEvent.stringify(false);
		}
		if (this._lottery) {
			json.lottery = this._lottery.stringify(false);
		}
		if (this._train) {
			json.train = this._train.stringify(false);
		}
		if (this._petManager) {
			json.petManager = this._petManager.stringify(false);
		}
		if (this._trialTower) {
			json.trialTower = this._trialTower.stringify(false);
		}
		if (this._mailBox) {
			json.mailBox = this._mailBox.stringify(false);
		}
		if (this._worldBoss) {
			json.worldBoss = this._worldBoss.stringify(false);
		}
		if (this._legionBoss) {
			json.legionBoss = this._legionBoss.stringify(false);
		}
		if (this._mission) {
			json.mission = this._mission.stringify(false);
		}
		if (this._welfare) {
			json.welfare = this._welfare.stringify(false);
		}
		if (this._talent) {
			json.talent = this._talent.stringify(false);
		}
		if (this._shopManager) {
			json.shopManager = this._shopManager.stringify(false);
		}
		if (this._handBook) {
			json.handBook = this._handBook.stringify(false);
		}
		if (this._gardenManager) {
			json.gardenManager = this._gardenManager.stringify(false);
		}
		if (this._huangXiaoxiManager) {
			json.huangXiaoxiManager = this._huangXiaoxiManager.stringify(false);
		}
		if (this._outerRewards) {
			json.outerRewards = this._outerRewards.stringify(false);
		}
		if (this._incId.size() > 0) {
			const ks = this._incId.getKeys();
			const vs = this._incId.getValues();
			json.incId = [ks, vs];
		}
		if (this._itemNum.size() > 0) {
			const ks = this._itemNum.getKeys();
			const vs = this._itemNum.getValues();
			json.itemNum = [ks, vs];
		}
		if (this._prayLevel.size() > 0) {
			const ks = this._prayLevel.getKeys();
			const vs = this._prayLevel.getValues();
			json.prayLevel = [ks, vs];
		}
		if (this._activity) {
			json.activity = this._activity.stringify(false);
		}
		if (this._arena) {
			json.arena = this._arena.stringify(false);
		}
		if (this._legion) {
			json.legion = this._legion.stringify(false);
		}
		if (this._title) {
			json.title = this._title.stringify(false);
		}
		if (this._chatManager) {
			json.chatManager = this._chatManager.stringify(false);
		}
		if (this._clientStorage) {
			json.clientStorage = this._clientStorage.stringify(false);
		}
		if (this._worldBoss2) {
			json.worldBoss2 = this._worldBoss2.stringify(false);
		}
		if (this._worldBoss3) {
			json.worldBoss3 = this._worldBoss3.stringify(false);
		}

		return toString ? JSON.stringify(json) : json;
	}


	/**反序列化*/
	public parse(jsonv: string | any): this {
		this.resetProperty();
		if (!jsonv) {
			return this;
		}
		const json = typeof (jsonv) === 'string' ? JSON.parse(jsonv) : jsonv;
		if (json.playerId) {
			this._playerId = json.playerId;
		}
		if (json.userId) {
			this._userId = json.userId;
		}
		if (json.channel) {
			this._channel = json.channel;
		}
		if (json.xunFengSdk) {
			this._xunFengSdk.destroy();
			this._xunFengSdk = XunFengSdk.create(json.xunFengSdk);
		}
		if (json.banned) {
			this._banned = json.banned;
		}
		if (json.playerInfo) {
			this._playerInfo.destroy();
			this._playerInfo = PlayerInfo.create(json.playerInfo);
		}
		if (json.server) {
			this._server.destroy();
			this._server = PlayerServer.create(json.server);
		}
		if (json.vip) {
			this._vip.destroy();
			this._vip = Vip.create(json.vip);
		}
		if (json.battleStage) {
			this._battleStage.destroy();
			this._battleStage = GameStage.create(json.battleStage);
		}
		if (json.equipManager) {
			this._equipManager.destroy();
			this._equipManager = EquipManager.create(json.equipManager);
		}
		if (json.randomEvent) {
			this._randomEvent.destroy();
			this._randomEvent = RandomEvent.create(json.randomEvent);
		}
		if (json.lottery) {
			this._lottery.destroy();
			this._lottery = Lottery.create(json.lottery);
		}
		if (json.train) {
			this._train.destroy();
			this._train = Train.create(json.train);
		}
		if (json.petManager) {
			this._petManager.destroy();
			this._petManager = PetManager.create(json.petManager);
		}
		if (json.trialTower) {
			this._trialTower.destroy();
			this._trialTower = TrialTower.create(json.trialTower);
		}
		if (json.mailBox) {
			this._mailBox.destroy();
			this._mailBox = MailBox.create(json.mailBox);
		}
		if (json.worldBoss) {
			this._worldBoss.destroy();
			this._worldBoss = WorldBoss.create(json.worldBoss);
		}
		if (json.legionBoss) {
			this._legionBoss.destroy();
			this._legionBoss = LegionBoss.create(json.legionBoss);
		}
		if (json.mission) {
			this._mission.destroy();
			this._mission = Mission.create(json.mission);
		}
		if (json.welfare) {
			this._welfare.destroy();
			this._welfare = Welfare.create(json.welfare);
		}
		if (json.talent) {
			this._talent.destroy();
			this._talent = Talent.create(json.talent);
		}
		if (json.shopManager) {
			this._shopManager.destroy();
			this._shopManager = ShopManager.create(json.shopManager);
		}
		if (json.handBook) {
			this._handBook.destroy();
			this._handBook = HandBook.create(json.handBook);
		}
		if (json.gardenManager) {
			this._gardenManager.destroy();
			this._gardenManager = GardenManager.create(json.gardenManager);
		}
		if (json.huangXiaoxiManager) {
			this._huangXiaoxiManager.destroy();
			this._huangXiaoxiManager = HuangXiaoxiManager.create(json.huangXiaoxiManager);
		}
		if (json.outerRewards) {
			this._outerRewards.destroy();
			this._outerRewards = OuterRewards.create(json.outerRewards);
		}
		if (json.incId) {
			const ks: number[] = json.incId[0];
			const vs: number[] = json.incId[1];
			if (ks && vs && ks.length === vs.length) {	//json
				this._incId.setKeyAndValueList(ks, vs);
			}
			else if (json.incId.getKeys && json.incId.getValues) {	//结构体
				const ks2 = json.incId.getKeys();
				const vs2 = json.incId.getValues();
				if (ks2 && vs2 && ks2.length === vs2.length) {
					for (let i = 0, len = vs2.length; i < len; i++) {
						this._incId.put(ks2[i], vs2[i]);	//重新添加，防止数据公用后被释放导致bug
					}
				}
			}
		}
		if (json.itemNum) {
			const ks: number[] = json.itemNum[0];
			const vs: number[] = json.itemNum[1];
			if (ks && vs && ks.length === vs.length) {	//json
				this._itemNum.setKeyAndValueList(ks, vs);
			}
			else if (json.itemNum.getKeys && json.itemNum.getValues) {	//结构体
				const ks2 = json.itemNum.getKeys();
				const vs2 = json.itemNum.getValues();
				if (ks2 && vs2 && ks2.length === vs2.length) {
					for (let i = 0, len = vs2.length; i < len; i++) {
						this._itemNum.put(ks2[i], vs2[i]);	//重新添加，防止数据公用后被释放导致bug
					}
				}
			}
		}
		if (json.prayLevel) {
			const ks: number[] = json.prayLevel[0];
			const vs: number[] = json.prayLevel[1];
			if (ks && vs && ks.length === vs.length) {	//json
				this._prayLevel.setKeyAndValueList(ks, vs);
			}
			else if (json.prayLevel.getKeys && json.prayLevel.getValues) {	//结构体
				const ks2 = json.prayLevel.getKeys();
				const vs2 = json.prayLevel.getValues();
				if (ks2 && vs2 && ks2.length === vs2.length) {
					for (let i = 0, len = vs2.length; i < len; i++) {
						this._prayLevel.put(ks2[i], vs2[i]);	//重新添加，防止数据公用后被释放导致bug
					}
				}
			}
		}
		if (json.activity) {
			this._activity.destroy();
			this._activity = Activity.create(json.activity);
		}
		if (json.arena) {
			this._arena.destroy();
			this._arena = Arena.create(json.arena);
		}
		if (json.legion) {
			this._legion.destroy();
			this._legion = LegionManager.create(json.legion);
		}
		if (json.title) {
			this._title.destroy();
			this._title = PlayerTitle.create(json.title);
		}
		if (json.chatManager) {
			this._chatManager.destroy();
			this._chatManager = ChatManager.create(json.chatManager);
		}
		if (json.clientStorage) {
			this._clientStorage.destroy();
			this._clientStorage = ClientStorage.create(json.clientStorage);
		}
		if (json.worldBoss2) {
			this._worldBoss2.destroy();
			this._worldBoss2 = WorldBoss.create(json.worldBoss2);
		}
		if (json.worldBoss3) {
			this._worldBoss3.destroy();
			this._worldBoss3 = WorldBoss.create(json.worldBoss3);
		}
		return this;
	}


	/**序列化-二进制*/
	public toBytes(byte: Byte): void {
		if (!byte) {
			return;
		}
		byte.writeUint32(this._playerId);
		byte.writeUint32(this._userId);
		byte.writeString(this._channel);
		this._xunFengSdk.toBytes(byte);
		byte.writeBool(this._banned);
		this._playerInfo.toBytes(byte);
		this._server.toBytes(byte);
		this._vip.toBytes(byte);
		this._battleStage.toBytes(byte);
		this._equipManager.toBytes(byte);
		this._randomEvent.toBytes(byte);
		this._lottery.toBytes(byte);
		this._train.toBytes(byte);
		this._petManager.toBytes(byte);
		this._trialTower.toBytes(byte);
		this._mailBox.toBytes(byte);
		this._worldBoss.toBytes(byte);
		this._legionBoss.toBytes(byte);
		this._mission.toBytes(byte);
		this._welfare.toBytes(byte);
		this._talent.toBytes(byte);
		this._shopManager.toBytes(byte);
		this._handBook.toBytes(byte);
		this._gardenManager.toBytes(byte);
		this._huangXiaoxiManager.toBytes(byte);
		this._outerRewards.toBytes(byte);
		//自增id
		{
			const ks = this._incId.getKeys();
			const vs = this._incId.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeUint8(ks[i]);
				byte.writeUint32(vs[i]);
			}
		}
		//道具数量
		{
			const ks = this._itemNum.getKeys();
			const vs = this._itemNum.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeInt32(ks[i]);
				byte.writeUint32(vs[i]);
			}
		}
		//祝福等级
		{
			const ks = this._prayLevel.getKeys();
			const vs = this._prayLevel.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeUint32(ks[i]);
				byte.writeUint16(vs[i]);
			}
		}
		this._activity.toBytes(byte);
		this._arena.toBytes(byte);
		this._legion.toBytes(byte);
		this._title.toBytes(byte);
		this._chatManager.toBytes(byte);
		this._clientStorage.toBytes(byte);
		this._worldBoss2.toBytes(byte);
		this._worldBoss3.toBytes(byte);
	}


	/**反序列化-二进制*/
	public fromBytes(byte: Byte): this {
		this.resetProperty();
		if (!byte) {
			return;
		}
		this._playerId = byte.readUint32();
		this._userId = byte.readUint32();
		this._channel = byte.readString();
		this._xunFengSdk.fromBytes(byte);
		this._banned = byte.readBool();
		this._playerInfo.fromBytes(byte);
		this._server.fromBytes(byte);
		this._vip.fromBytes(byte);
		this._battleStage.fromBytes(byte);
		this._equipManager.fromBytes(byte);
		this._randomEvent.fromBytes(byte);
		this._lottery.fromBytes(byte);
		this._train.fromBytes(byte);
		this._petManager.fromBytes(byte);
		this._trialTower.fromBytes(byte);
		this._mailBox.fromBytes(byte);
		this._worldBoss.fromBytes(byte);
		this._legionBoss.fromBytes(byte);
		this._mission.fromBytes(byte);
		this._welfare.fromBytes(byte);
		this._talent.fromBytes(byte);
		this._shopManager.fromBytes(byte);
		this._handBook.fromBytes(byte);
		this._gardenManager.fromBytes(byte);
		this._huangXiaoxiManager.fromBytes(byte);
		this._outerRewards.fromBytes(byte);
		//自增id
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readUint8();
				const v = byte.readUint32();
				this._incId.put(k, v);
			}
		}
		//道具数量
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readInt32();
				const v = byte.readUint32();
				this._itemNum.put(k, v);
			}
		}
		//祝福等级
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readUint32();
				const v = byte.readUint16();
				this._prayLevel.put(k, v);
			}
		}
		this._activity.fromBytes(byte);
		this._arena.fromBytes(byte);
		this._legion.fromBytes(byte);
		this._title.fromBytes(byte);
		this._chatManager.fromBytes(byte);
		this._clientStorage.fromBytes(byte);
		this._worldBoss2.fromBytes(byte);
		this._worldBoss3.fromBytes(byte);
		return this;
	}


	/**克隆*/
	public clone(): Player {
		const byte = Byte.createFromPool();
		this.toBytes(byte);
		byte.pos = 0;
		const clonev = Player.create().fromBytes(byte);
		Byte.recoverToPool(byte);
		return clonev;
	}


	/**处理更新*/
	public processUpdate(jsonv: string): void {
		if (!jsonv) {
			return;
		}

		const eventID = Player.EVENT_ID;
		const us = JSON.parse(jsonv);

		for (let i = 0, len = us.length; i < len;) {
			const idx = us[i];
			//玩家id
			if (idx === E_Player.PLAYER_ID) {
				const oldv = this._playerId;
				this._playerId = us[i + 1];
				IAsync.dispatch(eventID, idx, this._playerId, oldv);
				i += 2;
				continue;
			}
			//用户id
			if (idx === E_Player.USER_ID) {
				const oldv = this._userId;
				this._userId = us[i + 1];
				IAsync.dispatch(eventID, idx, this._userId, oldv);
				i += 2;
				continue;
			}
			//注册渠道
			if (idx === E_Player.CHANNEL) {
				const oldv = this._channel;
				this._channel = us[i + 1];
				IAsync.dispatch(eventID, idx, this._channel, oldv);
				i += 2;
				continue;
			}
			//巽风sdk信息
			if (idx === E_Player.XUN_FENG_SDK) {
				const fui: string = us[i + 1];
				if (this._xunFengSdk) {
					this._xunFengSdk.processUpdate(fui);
				}
				else {
					console.error('Player xunFengSdk is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//是否封号
			if (idx === E_Player.BANNED) {
				const oldv = this._banned;
				this._banned = us[i + 1];
				IAsync.dispatch(eventID, idx, this._banned, oldv);
				i += 2;
				continue;
			}
			//玩家信息
			if (idx === E_Player.PLAYER_INFO) {
				const fui: string = us[i + 1];
				if (this._playerInfo) {
					this._playerInfo.processUpdate(fui);
				}
				else {
					console.error('Player playerInfo is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//服务器信息
			if (idx === E_Player.SERVER) {
				const fui: string = us[i + 1];
				if (this._server) {
					this._server.processUpdate(fui);
				}
				else {
					console.error('Player server is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//vip信息
			if (idx === E_Player.VIP) {
				const fui: string = us[i + 1];
				if (this._vip) {
					this._vip.processUpdate(fui);
				}
				else {
					console.error('Player vip is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//战斗场景信息
			if (idx === E_Player.BATTLE_STAGE) {
				const fui: string = us[i + 1];
				if (this._battleStage) {
					this._battleStage.processUpdate(fui);
				}
				else {
					console.error('Player battleStage is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//装备
			if (idx === E_Player.EQUIP_MANAGER) {
				const fui: string = us[i + 1];
				if (this._equipManager) {
					this._equipManager.processUpdate(fui);
				}
				else {
					console.error('Player equipManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//随机事件
			if (idx === E_Player.RANDOM_EVENT) {
				const fui: string = us[i + 1];
				if (this._randomEvent) {
					this._randomEvent.processUpdate(fui);
				}
				else {
					console.error('Player randomEvent is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//抽卡
			if (idx === E_Player.LOTTERY) {
				const fui: string = us[i + 1];
				if (this._lottery) {
					this._lottery.processUpdate(fui);
				}
				else {
					console.error('Player lottery is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//训练
			if (idx === E_Player.TRAIN) {
				const fui: string = us[i + 1];
				if (this._train) {
					this._train.processUpdate(fui);
				}
				else {
					console.error('Player train is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//宠物
			if (idx === E_Player.PET_MANAGER) {
				const fui: string = us[i + 1];
				if (this._petManager) {
					this._petManager.processUpdate(fui);
				}
				else {
					console.error('Player petManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//试练塔
			if (idx === E_Player.TRIAL_TOWER) {
				const fui: string = us[i + 1];
				if (this._trialTower) {
					this._trialTower.processUpdate(fui);
				}
				else {
					console.error('Player trialTower is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//邮箱
			if (idx === E_Player.MAIL_BOX) {
				const fui: string = us[i + 1];
				if (this._mailBox) {
					this._mailBox.processUpdate(fui);
				}
				else {
					console.error('Player mailBox is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//世界boss
			if (idx === E_Player.WORLD_BOSS) {
				const fui: string = us[i + 1];
				if (this._worldBoss) {
					this._worldBoss.processUpdate(fui);
				}
				else {
					console.error('Player worldBoss is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//军团boss
			if (idx === E_Player.LEGION_BOSS) {
				const fui: string = us[i + 1];
				if (this._legionBoss) {
					this._legionBoss.processUpdate(fui);
				}
				else {
					console.error('Player legionBoss is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//任务
			if (idx === E_Player.MISSION) {
				const fui: string = us[i + 1];
				if (this._mission) {
					this._mission.processUpdate(fui);
				}
				else {
					console.error('Player mission is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//福利
			if (idx === E_Player.WELFARE) {
				const fui: string = us[i + 1];
				if (this._welfare) {
					this._welfare.processUpdate(fui);
				}
				else {
					console.error('Player welfare is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//天赋
			if (idx === E_Player.TALENT) {
				const fui: string = us[i + 1];
				if (this._talent) {
					this._talent.processUpdate(fui);
				}
				else {
					console.error('Player talent is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//商店
			if (idx === E_Player.SHOP_MANAGER) {
				const fui: string = us[i + 1];
				if (this._shopManager) {
					this._shopManager.processUpdate(fui);
				}
				else {
					console.error('Player shopManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//图鉴
			if (idx === E_Player.HAND_BOOK) {
				const fui: string = us[i + 1];
				if (this._handBook) {
					this._handBook.processUpdate(fui);
				}
				else {
					console.error('Player handBook is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//庭院管理器
			if (idx === E_Player.GARDEN_MANAGER) {
				const fui: string = us[i + 1];
				if (this._gardenManager) {
					this._gardenManager.processUpdate(fui);
				}
				else {
					console.error('Player gardenManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//黄小西管理器
			if (idx === E_Player.HUANG_XIAOXI_MANAGER) {
				const fui: string = us[i + 1];
				if (this._huangXiaoxiManager) {
					this._huangXiaoxiManager.processUpdate(fui);
				}
				else {
					console.error('Player huangXiaoxiManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//玩家待领取的外部奖励
			if (idx === E_Player.OUTER_REWARDS) {
				const fui: string = us[i + 1];
				if (this._outerRewards) {
					this._outerRewards.processUpdate(fui);
				}
				else {
					console.error('Player outerRewards is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}

			//自增id
			if (idx === E_Player.INC_ID) {
				const k: number = us[i + 1];
				const newv :number = us[i + 2];
				const oldv = this.putIncId(k, newv);
				IAsync.dispatch(eventID, idx, k, newv, oldv);
				i += 3;
				continue;
			}

			//道具数量
			if (idx === E_Player.ITEM_NUM) {
				const k: number = us[i + 1];
				const newv :number = us[i + 2];
				const oldv = this.putItemNum(k, newv);
				IAsync.dispatch(eventID, idx, k, newv, oldv);
				i += 3;
				continue;
			}

			//祝福等级
			if (idx === E_Player.PRAY_LEVEL) {
				const k: number = us[i + 1];
				const newv :number = us[i + 2];
				const oldv = this.putPrayLevel(k, newv);
				IAsync.dispatch(eventID, idx, k, newv, oldv);
				i += 3;
				continue;
			}
			//活动
			if (idx === E_Player.ACTIVITY) {
				const fui: string = us[i + 1];
				if (this._activity) {
					this._activity.processUpdate(fui);
				}
				else {
					console.error('Player activity is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//竞技场
			if (idx === E_Player.ARENA) {
				const fui: string = us[i + 1];
				if (this._arena) {
					this._arena.processUpdate(fui);
				}
				else {
					console.error('Player arena is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//军团
			if (idx === E_Player.LEGION) {
				const fui: string = us[i + 1];
				if (this._legion) {
					this._legion.processUpdate(fui);
				}
				else {
					console.error('Player legion is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//称号
			if (idx === E_Player.TITLE) {
				const fui: string = us[i + 1];
				if (this._title) {
					this._title.processUpdate(fui);
				}
				else {
					console.error('Player title is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//聊天
			if (idx === E_Player.CHAT_MANAGER) {
				const fui: string = us[i + 1];
				if (this._chatManager) {
					this._chatManager.processUpdate(fui);
				}
				else {
					console.error('Player chatManager is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//客户端自定义存储
			if (idx === E_Player.CLIENT_STORAGE) {
				const fui: string = us[i + 1];
				if (this._clientStorage) {
					this._clientStorage.processUpdate(fui);
				}
				else {
					console.error('Player clientStorage is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//世界boss2
			if (idx === E_Player.WORLD_BOSS2) {
				const fui: string = us[i + 1];
				if (this._worldBoss2) {
					this._worldBoss2.processUpdate(fui);
				}
				else {
					console.error('Player worldBoss2 is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}
			//世界boss3
			if (idx === E_Player.WORLD_BOSS3) {
				const fui: string = us[i + 1];
				if (this._worldBoss3) {
					this._worldBoss3.processUpdate(fui);
				}
				else {
					console.error('Player worldBoss3 is null when update.');
				}
				IAsync.dispatch(eventID, idx);
				i += 2;
				continue;
			}

			console.error('[Struct Data] can not find enum in Player with idx = ' + idx + ', version maybe wrong.')
		}

		//全更事件
		ITimer.callLater(this, this.dispatchTotalUpdate);
	}


	/**比对不一致结果*/
	public getCompareInfo(other: Player): string {
		if (!other) {
			return null;
		}

		const updates: any[] = [];

		if (this._playerId !== other._playerId) {
			updates.push(E_Player.PLAYER_ID, this._playerId);
		}
		if (this._userId !== other._userId) {
			updates.push(E_Player.USER_ID, this._userId);
		}
		if (this._channel !== other._channel) {
			updates.push(E_Player.CHANNEL, this._channel);
		}
		//巽风sdk信息
		{
			const ui = this._xunFengSdk.getCompareInfo(other._xunFengSdk);
			if (ui && ui.length > 0) {
				updates.push(E_Player.XUN_FENG_SDK, ui);
			}
		}
		if (this._banned !== other._banned) {
			updates.push(E_Player.BANNED, this._banned);
		}
		//玩家信息
		{
			const ui = this._playerInfo.getCompareInfo(other._playerInfo);
			if (ui && ui.length > 0) {
				updates.push(E_Player.PLAYER_INFO, ui);
			}
		}
		//服务器信息
		{
			const ui = this._server.getCompareInfo(other._server);
			if (ui && ui.length > 0) {
				updates.push(E_Player.SERVER, ui);
			}
		}
		//vip信息
		{
			const ui = this._vip.getCompareInfo(other._vip);
			if (ui && ui.length > 0) {
				updates.push(E_Player.VIP, ui);
			}
		}
		//战斗场景信息
		{
			const ui = this._battleStage.getCompareInfo(other._battleStage);
			if (ui && ui.length > 0) {
				updates.push(E_Player.BATTLE_STAGE, ui);
			}
		}
		//装备
		{
			const ui = this._equipManager.getCompareInfo(other._equipManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.EQUIP_MANAGER, ui);
			}
		}
		//随机事件
		{
			const ui = this._randomEvent.getCompareInfo(other._randomEvent);
			if (ui && ui.length > 0) {
				updates.push(E_Player.RANDOM_EVENT, ui);
			}
		}
		//抽卡
		{
			const ui = this._lottery.getCompareInfo(other._lottery);
			if (ui && ui.length > 0) {
				updates.push(E_Player.LOTTERY, ui);
			}
		}
		//训练
		{
			const ui = this._train.getCompareInfo(other._train);
			if (ui && ui.length > 0) {
				updates.push(E_Player.TRAIN, ui);
			}
		}
		//宠物
		{
			const ui = this._petManager.getCompareInfo(other._petManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.PET_MANAGER, ui);
			}
		}
		//试练塔
		{
			const ui = this._trialTower.getCompareInfo(other._trialTower);
			if (ui && ui.length > 0) {
				updates.push(E_Player.TRIAL_TOWER, ui);
			}
		}
		//邮箱
		{
			const ui = this._mailBox.getCompareInfo(other._mailBox);
			if (ui && ui.length > 0) {
				updates.push(E_Player.MAIL_BOX, ui);
			}
		}
		//世界boss
		{
			const ui = this._worldBoss.getCompareInfo(other._worldBoss);
			if (ui && ui.length > 0) {
				updates.push(E_Player.WORLD_BOSS, ui);
			}
		}
		//军团boss
		{
			const ui = this._legionBoss.getCompareInfo(other._legionBoss);
			if (ui && ui.length > 0) {
				updates.push(E_Player.LEGION_BOSS, ui);
			}
		}
		//任务
		{
			const ui = this._mission.getCompareInfo(other._mission);
			if (ui && ui.length > 0) {
				updates.push(E_Player.MISSION, ui);
			}
		}
		//福利
		{
			const ui = this._welfare.getCompareInfo(other._welfare);
			if (ui && ui.length > 0) {
				updates.push(E_Player.WELFARE, ui);
			}
		}
		//天赋
		{
			const ui = this._talent.getCompareInfo(other._talent);
			if (ui && ui.length > 0) {
				updates.push(E_Player.TALENT, ui);
			}
		}
		//商店
		{
			const ui = this._shopManager.getCompareInfo(other._shopManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.SHOP_MANAGER, ui);
			}
		}
		//图鉴
		{
			const ui = this._handBook.getCompareInfo(other._handBook);
			if (ui && ui.length > 0) {
				updates.push(E_Player.HAND_BOOK, ui);
			}
		}
		//庭院管理器
		{
			const ui = this._gardenManager.getCompareInfo(other._gardenManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.GARDEN_MANAGER, ui);
			}
		}
		//黄小西管理器
		{
			const ui = this._huangXiaoxiManager.getCompareInfo(other._huangXiaoxiManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.HUANG_XIAOXI_MANAGER, ui);
			}
		}
		//玩家待领取的外部奖励
		{
			const ui = this._outerRewards.getCompareInfo(other._outerRewards);
			if (ui && ui.length > 0) {
				updates.push(E_Player.OUTER_REWARDS, ui);
			}
		}

		//自增id
		{
			const idx = E_Player.INC_ID;
			const ks1 = this._incId.getKeys();
			const ks2 = other._incId.getKeys();
			const vs1 = this._incId.getValues();
			const vs2 = other._incId.getValues();
			const rs = MathUtils.intersectSortedArray(ks1, ks2, vs1, vs2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getIncId(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getIncId(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}

		//道具数量
		{
			const idx = E_Player.ITEM_NUM;
			const ks1 = this._itemNum.getKeys();
			const ks2 = other._itemNum.getKeys();
			const vs1 = this._itemNum.getValues();
			const vs2 = other._itemNum.getValues();
			const rs = MathUtils.intersectSortedArray(ks1, ks2, vs1, vs2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getItemNum(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getItemNum(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}

		//祝福等级
		{
			const idx = E_Player.PRAY_LEVEL;
			const ks1 = this._prayLevel.getKeys();
			const ks2 = other._prayLevel.getKeys();
			const vs1 = this._prayLevel.getValues();
			const vs2 = other._prayLevel.getValues();
			const rs = MathUtils.intersectSortedArray(ks1, ks2, vs1, vs2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getPrayLevel(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getPrayLevel(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}
		//活动
		{
			const ui = this._activity.getCompareInfo(other._activity);
			if (ui && ui.length > 0) {
				updates.push(E_Player.ACTIVITY, ui);
			}
		}
		//竞技场
		{
			const ui = this._arena.getCompareInfo(other._arena);
			if (ui && ui.length > 0) {
				updates.push(E_Player.ARENA, ui);
			}
		}
		//军团
		{
			const ui = this._legion.getCompareInfo(other._legion);
			if (ui && ui.length > 0) {
				updates.push(E_Player.LEGION, ui);
			}
		}
		//称号
		{
			const ui = this._title.getCompareInfo(other._title);
			if (ui && ui.length > 0) {
				updates.push(E_Player.TITLE, ui);
			}
		}
		//聊天
		{
			const ui = this._chatManager.getCompareInfo(other._chatManager);
			if (ui && ui.length > 0) {
				updates.push(E_Player.CHAT_MANAGER, ui);
			}
		}
		//客户端自定义存储
		{
			const ui = this._clientStorage.getCompareInfo(other._clientStorage);
			if (ui && ui.length > 0) {
				updates.push(E_Player.CLIENT_STORAGE, ui);
			}
		}
		//世界boss2
		{
			const ui = this._worldBoss2.getCompareInfo(other._worldBoss2);
			if (ui && ui.length > 0) {
				updates.push(E_Player.WORLD_BOSS2, ui);
			}
		}
		//世界boss3
		{
			const ui = this._worldBoss3.getCompareInfo(other._worldBoss3);
			if (ui && ui.length > 0) {
				updates.push(E_Player.WORLD_BOSS3, ui);
			}
		}

		const jsonv = updates.length === 0 ? null : JSON.stringify(updates);
		return jsonv;
	}


	/**全部更新*/
	protected dispatchTotalUpdate(): void {
		IAsync.dispatch(Player.TOTAL_EVENT_ID, this.getV(0));
	}

}
